import Cookies from "js-cookie";
import { BASE_API, wxAuthUrl } from "service/env";
// import CryptoJS from 'common/aes'
import { Base64 } from "js-base64";

const TokenKey = "token";
const OPenIdKey = "open-id";
const UserInfo = "user-info";

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}



export function getOpenID() {
  return Cookies.get(OPenIdKey)
}

export function setOpenID(openid) {
  return Cookies.set(OPenIdKey, openid)
}

export function getUID() {
  return Cookies.get('uid')
}

export function setUID(uid) {
  return Cookies.set('uid', uid)
}

export function getPhone() {
  return Cookies.get("phone")
}

export function setPhone(phone) {
  return Cookies.set("phone", phone)
}

export function removeOpenID() {
  return Cookies.remove(OPenIdKey)
}


export function getUserInfo() {
  return (Cookies.getJSON(UserInfo) || {})
}

export function setUserInfo(info) {
  return Cookies.set(UserInfo, info)
}

export function removeUserInfo() {
  return Cookies.remove(UserInfo)
}

export function setTag() {
  return Cookies.set("tag", 1, 0.001)
}

export function getTag() {
  return Cookies.get("tag")
}


export function setCode(code) {
  return Cookies.set("code", code)
}

export function getCode() {
  return Cookies.get("code")
}



export function setTpCode(tpcode) {
  return Cookies.set("tpcode", tpcode)
}

export function getTpCode() {
  return Cookies.get("tpcode")
}


export function setOrg(org) {
  return Cookies.set("org", org)
}

export function getOrg() {
  return Cookies.get("org")
}


export function setType(type) {
  return Cookies.set("type", type)
}

export function getType() {
  return Cookies.get("type")
}

export function getChannelToken() {
  return Cookies.get("channeltoken")
}

export function setChannelToken(token) {
  return Cookies.set("channeltoken", token,{ expires: 30 })
}

export function getRId() {
  return Cookies.get("rid")
}
export function setRId(rid) {
  return Cookies.set("rid", rid)
}




export function getHospitalId() {
  return Cookies.get("HospitalId")
}
export function setHospitalId(id) {
  return Cookies.set("HospitalId", id)
}




export function getCrc() {
  return Cookies.get("crc")
}
export function setCrc(crc) {
  return Cookies.set("crc", crc)
}


export function gethzTestStatus() {
  return Cookies.get("hzTestStatus")
}
export function sethzTestStatus(hzTestStatus) {
  return Cookies.set("hzTestStatus", hzTestStatus)
}

export function getWxAuth() {
  let rd = location.href;
  rd = Base64.encode(rd, "zhanwangzhanwang").toString();

  let redirect_uri = encodeURIComponent(
    `${BASE_API}/user/weChat/auth?rd=${rd}`
  );
  // console.log(`${wxAuthUrl}redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=123#wechat_redirect`)
  location.replace(
    `${wxAuthUrl}redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=123#wechat_redirect`
  );
}
